package etcd

import (
	clientv3 "go.etcd.io/etcd/client/v3"
	"strings"
	"time"
)

type EtcdV3Wrapper struct {
	cli         *clientv3.Client
	dialTimeout int64
	timeout     int64
}

func NewEtcdV3Wrapper(endpoints string, dialTimeout int64, timeout int64) (*EtcdV3Wrapper, error) {
	endpointsArr := strings.Split(endpoints, ",")
	etcdConfig := clientv3.Config{
		Endpoints:   endpointsArr,
		DialTimeout: time.Duration(dialTimeout) * time.Second,
	}

	cli, err := clientv3.New(etcdConfig)
	if err != nil {
		return nil, err
	}

	return &EtcdV3Wrapper{
		cli:         cli,
		dialTimeout: dialTimeout,
		timeout:     timeout,
	}, nil
}

